/**
 * Created by 7097 on 2021/6/17.
 */

public with sharing class AcceptancePerformanceController {
    public String infoUserName { private set; get; }
    public List<AccountsReceivableStatement__c> acceptancePerformances { private set; get; }
    public String users { private set; get; }
    public String performancesDataJson { private set; get; }
    public String statementsDataJson { private set; get; }
    public AcceptancePerformanceController() {
    }

    public void init() {
        this.infoUserName =  UserInfo.getName();
        List<User> usersList = [SELECT ExuserCode__c FROM User WHERE Name = :UserInfo.getName()];
        String str = usersList[0].ExuserCode__c;
        /*
                SELECT Id,CentralizedCompany__c,BillingCompany__c,AccountCode__c,CustomerAttributes__c,Customer__c,Year__c,Quarterly__c,CreditPeriod__c,WhetherNewSalesman__c,
                        AcceptancePerformance__r.Manager__c,LastReceivables__c,CurrentReceivables__c,LastOverdueAmount__c,CurrentOverdueAmount__c,ReagentAccessoriesBackAmount__c,ReagentAccessoriesSalesRevenue__c,
                        Overdue__c,Over3MonthsOfOverdueDate__c,Over6MonthsOfOverdueDate__c,AdjustmentAmount1__c,OverdueAfterAdjustment__c,OverdueChangeRatio__c,Score__c,Reconciliation__c,
                        Deduction1__c,Deduction2__c,AccountDeductionInThisQuarterAdjust__c,AdjustmentAmount2__c,AdjustmentAmount3__c,DeductionAfterAdjustment1__c,
                        DeductionAfterAdjustment2__c,Deduction3__c,Deduction4__c,AcceptancePerformance__r.Agent__c,AcceptancePerformance__r.SalerNumber__c,AcceptancePerformance__r.ManagerNumber__c
                FROM AccountsReceivableStatement__c
                WHERE AcceptancePerformance__r.SalerNumber__c = :str
        * */
        acceptancePerformances = [
                SELECT Id,CentralizedCompany__c,BillingCompany__c,AccountCode__c,CustomerAttributes__c,Customer__c,CreditPeriod__c,WhetherNewSalesman__c,
                        AcceptancePerformance__r.Manager__c,LastReceivables__c,CurrentReceivables__c,LastOverdueAmount__c,CurrentOverdueAmount__c,ReagentAccessoriesBackAmount__c,ReagentAccessoriesSalesRevenue__c,
                        Overdue__c,Over3MonthsOfOverdueDate__c,Over6MonthsOfOverdueDate__c,AdjustmentAmount1__c,OverdueAfterAdjustment__c,OverdueChangeRatio__c,Score__c,Reconciliation__c,
                        Deduction1__c,Deduction2__c,AccountDeductionInThisQuarterAdjust__c,AdjustmentAmount2__c,AdjustmentAmount3__c,DeductionAfterAdjustment1__c,
                        DeductionAfterAdjustment2__c,Deduction3__c,Deduction4__c,AcceptancePerformance__r.Agent__c,AcceptancePerformance__r.SalerNumber__c,AcceptancePerformance__r.ManagerNumber__c,AcceptancePerformance__r.KpiPeriod__c,
                        AcceptancePerformance__r.Owner.Name
                FROM AccountsReceivableStatement__c WHERE AcceptancePerformance__c = 'a1v0k000005UrIF'

        ];
        
        List<AccountsReceivableStatement__c> statements = [SELECT Id FROM AccountsReceivableStatement__c LIMIT 5];
        statementsDataJson = EncodingUtil.urlEncode(JSON.serialize(statements), 'UTF-8'); //a1s0k0000008wzoAAA a1v0k000000EKsuAAG
        users = EncodingUtil.urlEncode(JSON.serialize(str), 'UTF-8');
        // 查不到绩效则返回null
        performancesDataJson = acceptancePerformances.size() > 0 ? EncodingUtil.urlEncode(JSON.serialize(acceptancePerformances), 'UTF-8') : EncodingUtil.urlEncode(JSON.serialize(null), 'UTF-8');
        this.infoUserName = EncodingUtil.urlEncode(JSON.serialize(infoUserName), 'UTF-8');
    }


    public void saveData(){
        /*AccountsReceivableStatement__c ars = new AccountsReceivableStatement__c();
        // {field:'ACCOUNTCODE_NC',title:'客户编码',width:120},
        //   {field:'ACCOUNTNAME',title:'客户名称',width:120},
        //   {field:'RECORDTYPE',title:'客户属性',width:120},
        //   {field:'TERMNAME',title:'信用期',width:120},
        ars.Customer__c = DataUtil.getStringValue(mo.get('ACCOUNTNAME'));
        ars.AccountCode__c =  DataUtil.getStringValue(mo.get('ACCOUNTCODE_NC'));
        ars.CustomerAttributes__c = DataUtil.getStringValue(mo.get('RECORDTYPE'));
        ars.CreditPeriod__c  = DataUtil.getStringValue(mo.get('TERMNAME'));
        //{field:'UNITSHORTNAME_NC',title:'开票公司',width:120},
        ars.BillingCompany__c =  DataUtil.getStringValue(mo.get('UNITSHORTNAME_NC'));
        //{field:'UNITSHORTNAME_GK',title:'归口公司',width:120},
        ars.CentralizedCompany__c =  DataUtil.getStringValue(mo.get('UNITSHORTNAME_GK'));
        ars.WhetherNewSalesman__c =   DataUtil.getStringValue(mo.get('SFXJS'));
        ars.Agent__c =  DataUtil.getStringValue(mo.get('SFDLYWY'));

        // {field:'SJDYSZE',title:'上季度应收<br/>总额',width:120},
        // {field:'BJDYSYE',title:'本季度应收<br/>余额',width:120},
        // {field:'ZJSJDCQZE',title:'截止上季度<br/>超期总额',width:120},
        //上季度应收总额
        ars.LastReceivables__c = DataUtil.getDecimalValue(mo.get('SJDYSZE'));
        //本季度应收余额
        ars.CurrentReceivables__c = DataUtil.getDecimalValue(mo.get('BJDYSYE'));
        // 截止上季度超期总额
        ars.LastOverdueAmount__c = DataUtil.getDecimalValue(mo.get('ZJSJDCQZE'));
        //       {field:'JZBJDCQZE',title:'截止本季度<br/>超期总额',width:120},

        ars.CurrentOverdueAmount__c = DataUtil.getDecimalValue(mo.get('JZBJDCQZE'));
        //{field:'MONEYMAIN',title:'本季度回款',width:120},
        ars.ReagentAccessoriesBackAmount__c = DataUtil.getDecimalValue(mo.get('MONEYMAIN'));

        //  {field:'TAXNMNY',title:'本季度销售<br/>收入',width:120},
        ars.ReagentAccessoriesSalesRevenue__c = DataUtil.getDecimalValue(mo.get('TAXNMNY'));

        //  {field:'CQESY',title:'超期1-3个月',width:120},
        ars.Overdue__c = DataUtil.getDecimalValue(mo.get('CQESY'));
        //{field:'CQSLY',title:'超期3-6个月',width:120},
        ars.Over3MonthsOfOverdueDate__c = DataUtil.getDecimalValue(mo.get('CQSLY'));
        //{field:'CQLYYS',title:'超期6个月以上',width:120},
        ars.Over6MonthsOfOverdueDate__c = DataUtil.getDecimalValue(mo.get('CQLYYS'));
        //{field:'BJDCQTZE',title:'本季度超期<br/>调整额',width:120},
        ars.AdjustmentAmount1__c = DataUtil.getDecimalValue(mo.get('BJDCQTZE'));

        //{field:'BJD_AD_CQ',title:'本季度调整<br/>后超期',width:120},
        ars.OverdueAfterAdjustment__c = DataUtil.getDecimalValue(mo.get('BJD_AD_CQ'));

        //{field:'BJD_AD_PER',title:'当期超期<br/>环比变动',width:120},
        ars.OverdueChangeRatio__c = DataUtil.getDecimalValue(mo.get('BJD_AD_PER'));
        //  {field:'BJD_AD_SCORE',title:'超期环<br/>比得分',width:120},
        ars.Score__c = DataUtil.getDecimalValue(mo.get('BJD_AD_SCORE'));
        //{field:'BJDZDWCQK',title:'本季度对账<br/>完成情况',width:120},
        //ars.Reconciliation__c = DataUtil.getStringValue(mo.get('BJDZDWCQK'));
        //{field:'BJD_AD_DZQK',title:'本季度对账<br/>扣款额',width:120},
        ars.Deduction1__c = DataUtil.getDecimalValue(mo.get('BJD_AD_DZQK'));
        //{field:'BJD_AD_CQQK',title:'超期30天/90<br/>天扣款',width:120},
        ars.Deduction2__c = DataUtil.getDecimalValue(mo.get('BJD_AD_CQQK'));
        //{field:'BJD_AD_XSQK',title:'无销售无<br/>回款扣款',width:120},
        ars.Deduction3__c = DataUtil.getDecimalValue(mo.get('BJD_AD_XSQK'));


        //{field:'BJDDZTZE',title:'本季度对账<br/>调整额',width:120},
        ars.AccountDeductionInThisQuarterAdjust__c = DataUtil.getDecimalValue(mo.get('BJDDZTZE'));
        //{field:'CQSJSTZE',title:'超期30天/90天<br/>超期调整额',width:120},
        ars.AdjustmentAmount2__c = DataUtil.getDecimalValue(mo.get('CQSJSTZE'));
        //{field:'WXSWHKGKTZE',title:'无销售无回款<br/>扣款调整',width:120},
        ars.AdjustmentAmount3__c = DataUtil.getDecimalValue(mo.get('WXSWHKGKTZE'));
        //{field:'BJD_ADA_DZQK',title:'本季度调整后<br/>对账扣款',width:120},
        ars.DeductionAfterAdjustment1__c = DataUtil.getDecimalValue(mo.get('BJD_ADA_DZQK'));
        //{field:'BJD_ADA_CQQK',title:'超期30天/90天<br/>调整后超期扣款',width:120},
        ars.DeductionAfterAdjustment2__c = DataUtil.getDecimalValue(mo.get('BJD_ADA_CQQK'));
        //{field:'BJD_ADA_XSQK',title:'调后无销售无<br/>回款扣款',width:120},
        ars.DeductionAfterAdjustment3__c = DataUtil.getDecimalValue(mo.get('BJD_ADA_XSQK'));
        //{field:'SJDGK',title:'上季度扣款',width:120},
        ars.Deduction4__c = DataUtil.getDecimalValue(mo.get('SJDGK'));*/

    }

}